package com.phjr.jicaimaoflutter;

import android.content.Intent;
import android.os.Bundle;

import io.flutter.app.FlutterActivity;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugins.GeneratedPluginRegistrant;

public class MainActivity extends FlutterActivity {
    private static final String        STAT_ACTIVITY_METHOD = "com.phjr.jicaimaoflutter/activity";
    private              MethodChannel mDartStartNativeActivity;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        GeneratedPluginRegistrant.registerWith(this);


        mDartStartNativeActivity = new MethodChannel(getFlutterView(), STAT_ACTIVITY_METHOD);
        mDartStartNativeActivity.setMethodCallHandler(new MethodChannel.MethodCallHandler() {
            @Override
            public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
                if (methodCall.method.equals("startProductActivity")) {
                    String reward = methodCall.argument("reward");
                    String regularProduct = methodCall.argument("regularProduct");
                    String welfare = methodCall.argument("welfare");
                    startProductActivity(reward, regularProduct, welfare);

                }
            }
        });
    }

    private void startProductActivity(String reward, String regularProduct, String welfare) {
        Bundle bundle = new Bundle();
        bundle.putString(ProductDetailActivity.REWARD, reward);
        bundle.putString(ProductDetailActivity.REGULARPRODUCT, regularProduct);
        bundle.putString(ProductDetailActivity.WELFARE, welfare);

        Intent intent = new Intent(this, ProductDetailActivity.class);
        intent.putExtras(bundle);
        startActivity(intent);

    }


}
